package pl.wroc.uni.ii.gdomo;


public class SelectionManager {
	private Cell selectedCell = null;
	private PlayBoard playBoard;
	
	public SelectionManager(PlayBoard playBoard) {
		this.playBoard = playBoard;
	}
	
	public void select(Cell c) {
		c.select();
		
		if (isFirstSelected(c)) {
			selectedCell = c;
		}
		if (isSecondSelected(c)) {
			playBoard.swapCellsPositionsAndRefreshState(selectedCell, c);
			selectedCell.select();
			c.select();
			selectedCell = null;
		}
		if (isUnSelected(c)) {
			selectedCell = null;
		}
	}

	private boolean isSecondSelected(Cell c) {
		return (c != selectedCell && c.isSelected());
	}

	private boolean isUnSelected(Cell c) {
		return (c == selectedCell && !c.isSelected());
	}

	private boolean isFirstSelected(Cell c) {
		return (selectedCell == null && c.isSelected());
	}
}
